package com.atguigu.srb.sms.service.impl;

import com.atguigu.srb.sms.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

/**
 * @author study
 * @version 1.0
 * @date 2021/4/30 15:34
 */
@Slf4j
@Service
public class SmsServiceImpl implements SmsService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void send(String mobile, String templateCode, HashMap<String, String> map) {
        final String code = map.get("code");
        log.info("{}-{}", mobile, code);
        //发送并设置超时时间
        redisTemplate.opsForValue().set("srb:sms:code:" + mobile, code, 1, TimeUnit.MINUTES);
    }
}
